/**
 * Copyright  2025, Hai Yue Xing He  ZHAO LIMIN
 *
 * @author              ZHAO LIMIN
 * @version             1.0.1
 * @since               2025-04
 * DataCheckValueError.ts     数据检查，用于检查数据是否符合要求，如数据类型、数据范围、数据格式等。
 */
export class DataCheckValueError extends Error {
  /**
   * Constructs an exception object that is thrown due to a developer error, e.g., invalid argument,
   * argument out of range, etc.  This exception should only be thrown during development;
   * it usually indicates a bug in the calling code.  This exception should never be
   * caught; instead the calling code should strive not to generate it.
   * <br /><br />
   * On the other hand, a {@link RuntimeError} indicates an exception that may
   * be thrown at runtime, e.g., out of memory, that the calling code should be prepared
   * to catch.
   *
   * @alias DataCheckValueError
   * @constructor
   * @extends Error
   *
   * @param {string} [message] The error message for this exception.
   *
   * @see RuntimeError
   */
  constructor(message: string) {
    super(message)
    this.name = 'DataCheckValueError'
    /**
     * The explanation for why this exception was thrown.
     * @type {string}
     * @readonly
     */
    this.message = message
    try {
      throw new Error()
    } catch (error) {
      if (error instanceof DataCheckValueError) {
        console.error('捕获到自定义错误:', error.message)
      } else {
        console.error('发生错误:', error)
      }
    }
  }
  /**
   *
   * @returns {string}
   */
  public toString(): string {
    const str = `${this.name}: ${this.message}`
    return str
  }

  /**
   * @private
   */
  private static throwInstantiationError(): DataCheckValueError {
    throw new DataCheckValueError(
      'This function defines an interface and should not be called directly.',
    )
  }
}
